let Time = {
  //获取当前时间戳
  getUnix: function (){
    let date = new Date();
    return date.getTime();
  },
  //获取今天0点0分0秒的时间戳
  getTodayUnix:function (){
    let date = new Date();
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    date.setMinutes(0);
    return date.getTime();
  },
  getYearUnix:function (){
    let date = new Date();
    date.setMonth(0);
    date.setDate(1);
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    date.setMilliseconds(0)
    return date.getTime();
  },
  //获取标准年月日
  getLastDate:function (time) {
    let date = new Date(time);
    let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
    let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    return date.getFullYear() + '-' + month +'-' + day;
  },
  //转换时间
  getFormatTime : function (time){
    //time转换为时间戳
    //转换成YYYY/MM/DD的格式
    let formatDate = new Date(time.replace(/-/g,'/'))
    let date = new Date(formatDate);
    let timeStamp = Date.parse(date);
    let now = this.getUnix();//当前时间戳
    let today = this.getTodayUnix();//今天0点时间戳
    let year = this.getYearUnix();//今年0点时间戳
    let timer = (now - timeStamp)/1000; //转换为秒级时间戳
    if(timer <= 0 || Math.floor(timer/60) <= 0){
      return '刚刚'
    }
    if(timer <= 3600){
      return Math.floor(timer/60) + '分钟前'
    }
    if(timer >= 3600 && (timeStamp = today > 0) ){
      return Math.floor(timer/3600) + '小时前'
    }
    if(timer/86400 <= 31){
      return Math.ceil(timer/86400) +'天前'
    }
    return this.getLastDate(timeStamp);

  }

};
export {Time}
